package dao;

import java.util.ArrayList;
import java.util.List;

import modele.Region;
import modele.Theme;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import services.persistance.BaseDAO;

public class RegionDao {
	
	public static void ajouterRegion(Region region) {
		BaseDAO.getInstance().ajouter(region);
	}

	public static void modifierRegion(Region region) {
		BaseDAO.getInstance().modifier(region);
	}

	public static void supprimerRegion(Region region) {
		BaseDAO.getInstance().supprimer(region);
	}

	public static Region getRegion(long idRegion) {
		return (Region) BaseDAO.getInstance().getObject(Region.class, idRegion);
	}
	
	public static List getListeRegions(long idAdmin)
	{
		List liste = new ArrayList<>();
//		liste.add(idAdmin);
//		liste.add("rCegion");
		return BaseDAO.getInstance().getListObject("queryListeNomEmplacements",liste);

	}
		
		
		
		
		
		
		
		
		
	public static List getListeNomRegions(long idAdmin)
	{
		List liste = new ArrayList<>();
//		liste.add(idAdmin);
//		liste.add("rCegion");
		return BaseDAO.getInstance().getListObject("queryListeNomRegions",liste);
	}
	
	public static ArrayList<Region> rechercherRegionsParCriteresParAdmin(Region region)
	{
		Criteria criteria = BaseDAO.getInstance().getSession().createCriteria(Region.class);
		criteria.add(Restrictions.like("nom", "%"+ region.getNom() +"%"));
		criteria.add(Restrictions.like("description", "%"+ region.getDescription() +"%"));
		//criteria.add(Restrictions.eq("population", region.getPopulation()));
		criteria.createCriteria("administrateur").add(Restrictions.eq("identifiant", region.getAdministrateur().getIdentifiant()));
		
		return (ArrayList<Region>) BaseDAO.getInstance().getListObjectByCriteria(criteria);
	}


}
